﻿Imports AugmentLib.Database
Imports System.Configuration.ConfigurationManager
Imports AugmentLib.InputOutput.Encryption
Imports AugmentLib.WebComponent

Partial Class strans
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("StaffId") Is Nothing Or Session("StaffType").ToString = "2" Then
            Response.Redirect("Default.aspx")
        Else
            lblStaffUID.Text = Session("StaffId").ToString
            lblStaffType.Text = Session("StaffType").ToString
        End If

        If Not Page.IsPostBack Then

            CBEBack.ConfirmText = "You are about to navigate away from this page. " & vbCrLf & "Changes will be discard!"

            If Not Session("Tid").ToString Is Nothing Then
                lblTransUID.Text = Session("Tid").ToString
                'Me.Session.Remove("Tid")
                LoadrbtTransactAs()
                LoadTransInfo()
                Dim strCoBroke As String = String.Empty
                If lblhidCoBrokeAgencyName.Text <> String.Empty Then
                    strCoBroke += "Agency Name : " & lblhidCoBrokeAgencyName.Text.Trim & "<br />"
                End If
                If lblhidCoBrokePhone.Text <> String.Empty Then
                    strCoBroke += "Phone : " & lblhidCoBrokePhone.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeMobile.Text <> String.Empty Then
                    strCoBroke += "Mobile : " & lblhidCoBrokeMobile.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeFax.Text <> String.Empty Then
                    strCoBroke += "Fax : " & lblhidCoBrokeFax.Text.Trim & "<br />"
                End If
                If lblhidCoBrokeEmail.Text <> String.Empty Then
                    strCoBroke += "Email : " & lblhidCoBrokeEmail.Text.Trim & "<br />"
                End If
                lblCoBroke.Attributes.Add("onmouseover", "return overlib('" & strCoBroke & "',ABOVE);")
            Else
                Response.Redirect("TransList.aspx")
            End If
        End If
    End Sub

    Private Sub LoadrbtTransactAs()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        objDB.dbVariable.SQLString = "SELECT SRYes, SCYes, SLYes, SIYes FROM AW_Property p INNER JOIN AW_SaleTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId WHERE TransactionId = @TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text.Trim))
        objDB.FillData(TempDT, "AW_SaleTransaction", Database.SQLCommandType.NormalString)
        objDB.CloseConnection()

        For Each row As Data.DataRow In TempDT.Rows
            If row.Item("SRYes").ToString = "1" Then
                rbtTransactAs.Items.Add(New ListItem("SR", "1"))
            End If
            If row.Item("SCYes").ToString = "1" Then
                rbtTransactAs.Items.Add(New ListItem("SC", "2"))
            End If
            If row.Item("SLYes").ToString = "1" Then
                rbtTransactAs.Items.Add(New ListItem("SL", "3"))
            End If
            If row.Item("SIYes").ToString = "1" Then
                rbtTransactAs.Items.Add(New ListItem("SI", "4"))
            End If
        Next
    End Sub

    Private Sub LoadTransInfo()
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()

        objDB.dbVariable.SQLString = "SELECT t.TransactionId, t.PropertyId, t.OpenFileRef, t.CloseFileRef, " & _
                                "p.UnitNumber + ', ' + r.Road + ', ' + o.Location + ', ' + s.State + ', ' + y.Country as 'Address', " & _
                                "j.Project, t.ListerId, t.TransactorId, L.Name as Lister, L.Initial as ListerInitial, t.ListDate, t.VendorType, t.VendorName1, t.VendorName2, " & _
                                "t.VendorName3, t.VendorCompany, t.VendorNRIC1, t.VendorNRIC2, t.VendorNRIC3, a.Name as Transactor, a.Initial as TransactorInitial, " & _
                                "t.VendorCompanyNo, ISNULL(t.VendorAddress, p.OwnerAddress) as 'VendorAddress', " & _
                                "ISNULL(t.VendorPhone, p.OwnerPhone) as 'VendorPhone', " & _
                                "ISNULL(t.VendorMobile, p.OwnerMobile) as 'VendorMobile', " & _
                                "ISNULL(t.VendorFax, p.OwnerFax) as 'VendorFax', " & _
                                "ISNULL(t.VendorContactPerson, p.OwnerName) as 'VendorContactPerson', " & _
                                "ISNULL(t.VendorEmail, p.OwnerEmail) as 'VendorEmail', " & _
                                "t.VendorReferral, t.VendorReferralName, t.VendorReferralNRIC, t.TransactDate, " & _
                                "t.VendorReferralContact, t.VendorReferralStatus, t.VendorReferralAmount, t.VendorReferralAmtSum, " & _
                                "t.AgencyFee, t.GST, t.GSTPaidBy, t.ListingFee, t.VendorSolicitorCompany, t.VendorSolicitorName, " & _
                                "t.VendorSolicitorEmail, t.VendorSolicitorAddress, t.VendorSolicitorPhone, t.VendorSolicitorFax, " & _
                                "t.PurchaserType, t.PurchaserName1, t.PurchaserName2, t.PurchaserName3, t.PurchaserCompany, " & _
                                "t.PurchaserNRIC1, t.PurchaserNRIC2, t.PurchaserNRIC3, t.PurchaserCompanyNo, t.PurchaserAddress, " & _
                                "PurchaserPhone, t.PurchaserMobile, t.PurchaserFax, t.PurchaserEmail, t.PurchaserReferral, " & _
                                "t.PurchaserReferralName, t.PurchaserReferralNRIC, t.PurchaserReferralContact, " & _
                                "t.PurchaserReferralStatus, t.PurchaserReferralAmount, t.PurchaserReferralAmtSum, t.PurchaserContactPerson, " & _
                                "t.DisbursementFee, t.PurchaserSolicitorCompany, t.PurchaserSolicitorName, t.PurchaserSolicitorEmail, " & _
                                "t.PurchaserSolicitorAddress, t.PurchaserSolicitorPhone, t.PurchaserSolicitorFax, t.CoBroke, " & _
                                "t.CoBrokeId, c.Name as CoBrokeName, c.AgencyName as CoBrokeAgencyName, c.Phone as CoBrokePhone, " & _
                                "c.Mobile as CobrokeMobile, c.Fax as CobrokeFax, c.Email as cobrokeEmail, t.TransListType, " & _
                                "t.TransactedPrice, t.Deposit, t.PaymentType, t.PaymentDate, t.Requisition, t.TotalAgencyFee, " & _
                                "t.ListerAmt, t.ReferralAmt, t.GovAmt, t.GrossAmount, P.SListerId " & _
                                "FROM AW_SaleTransaction t LEFT JOIN AW_Staff L on t.ListerId = L.StaffId LEFT JOIN AW_Staff a on t.TransactorId = a.StaffId " & _
                                "LEFT JOIN AW_CoBroke c on t.CoBrokeId = c.CoBrokeId LEFT OUTER JOIN AW_Property p ON p.PropertyId = t.PropertyId " & _
                                "LEFT OUTER JOIN AW_Road r ON p.RoadId = r.RoadId LEFT OUTER JOIN AW_Location o ON r.LocationId = o.LocationId " & _
                                "LEFT OUTER JOIN AW_State s ON o.StateId = s.StateId LEFT OUTER JOIN AW_Country y ON s.CountryId = y.CountryId " & _
                                "LEFT OUTER JOIN AW_Project j ON p.ProjectId = j.ProjectId WHERE TransactionID=@TransId"
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text.Trim))
        objDB.FillData(TempDT, "AW_SaleTransaction", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In TempDT.Rows
            lblhidPropertyId.Text = ReadRow.Item("PropertyId").ToString
            'txtInvoiceNumber.Text = ReadRow.Item("InvoiceNumber").ToString
            txtOpenFileNumber.Text = ReadRow.Item("OpenFileRef").ToString
            If ReadRow.Item("ListerId").ToString = "" Then
                lblhidListerID.Text = ReadRow.Item("SListerId").ToString
            Else
                lblhidListerID.Text = ReadRow.Item("ListerId").ToString
            End If
            lblhidTransactorId.Text = ReadRow.Item("TransactorId").ToString
            txtLister.Text = ReadRow.Item("ListerInitial").ToString
            lblTransactor.Text = ReadRow.Item("TransactorInitial").ToString
            'txtLister.Text = ReadRow.Item("Lister").ToString
            'lblTransactor.Text = ReadRow.Item("Transactor").ToString
            If ReadRow.Item("ListDate").ToString = "" Then
                txtListDate.Text = ""
            Else
                txtListDate.Text = Format(ReadRow.Item("ListDate"), "dd-MMM-yyyy")
            End If
            If ReadRow.Item("TransactDate").ToString = "" Then
                lblTransactDate.Text = ""
            Else
                lblTransactDate.Text = Format(ReadRow.Item("TransactDate"), "dd-MMM-yyyy")
            End If
            If ReadRow.Item("Project").ToString = "" Then
                trProjectName.Visible = False
            Else
                trProjectName.Visible = True
                txtProjectName.Text = ReadRow.Item("Project").ToString
            End If
            txtPremiseName.Text = ReadRow.Item("Address").ToString
            '--Vendor--
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkVendorCompanyInfo", "checkVendorCompanyInfo();", True)
            If ReadRow.Item("VendorType").ToString = "1" Then   'Company
                chkVendorCompany.Checked = True
            End If
            txtVendorCompanyName.Text = ReadRow.Item("VendorCompany").ToString
            txtVendorCompanyNo.Text = ReadRow.Item("VendorCompanyNo").ToString
            txtVendorName1.Text = ReadRow.Item("VendorName1").ToString
            txtVendorName2.Text = ReadRow.Item("VendorName2").ToString
            txtVendorName3.Text = ReadRow.Item("VendorName3").ToString
            txtVendorNric1.Text = ReadRow.Item("VendorNRIC1").ToString
            txtVendorNric2.Text = ReadRow.Item("VendorNRIC2").ToString
            txtVendorNric3.Text = ReadRow.Item("VendorNRIC3").ToString

            txtVendorContactPerson.Text = ReadRow.Item("VendorContactPerson").ToString
            txtVendorAddress.Text = ReadRow.Item("VendorAddress").ToString
            txtVendorPhone.Text = ReadRow.Item("VendorPhone").ToString
            txtVendorMobile.Text = ReadRow.Item("VendorMobile").ToString
            txtVendorFax.Text = ReadRow.Item("VendorFax").ToString
            txtVendorEmail.Text = ReadRow.Item("VendorEmail").ToString
            ddlVendorRefer.SelectedValue = ReadRow.Item("VendorReferral").ToString
            'hide vendor if select no
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkVendorRefer", "checkVendorRefer();", True)
            txtVendorReferName.Text = ReadRow.Item("VendorReferralName").ToString
            txtVendorReferNRIC.Text = ReadRow.Item("VendorReferralNRIC").ToString
            txtVendorReferContact.Text = ReadRow.Item("VendorReferralContact").ToString
            ddlVendorReferStatus.SelectedValue = ReadRow.Item("VendorReferralStatus").ToString
            If ReadRow.Item("VendorReferralAmount").ToString = "" Then
                txtVendorReferAmt.Text = "0.00"
            Else
                txtVendorReferAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("VendorReferralAmount"))
            End If
            txtVendorSolicitorCompName.Text = ReadRow.Item("VendorSolicitorCompany").ToString
            txtVendorSolicitorContactPerson.Text = ReadRow.Item("VendorSolicitorName").ToString
            txtVendorSolicitorEmail.Text = ReadRow.Item("VendorSolicitorEmail").ToString
            txtVendorSolicitorsAddress.Text = ReadRow.Item("VendorSolicitorAddress").ToString
            txtVendorSolicitorsPhone.Text = ReadRow.Item("VendorSolicitorPhone").ToString
            txtVendorSolicitorsFax.Text = ReadRow.Item("VendorSolicitorFax").ToString
            '--Purchaser--
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkPurcCompanyInfo", "checkPurcCompanyInfo();", True)
            If ReadRow.Item("PurchaserType").ToString = "1" Then   'Company
                chkPurcCompany.Checked = True
            End If
            txtPurcCompanyName.Text = ReadRow.Item("PurchaserCompany").ToString
            txtPurcCompanyNo.Text = ReadRow.Item("PurchaserCompanyNo").ToString
            txtPurcName1.Text = ReadRow.Item("PurchaserName1").ToString
            txtPurcName2.Text = ReadRow.Item("PurchaserName2").ToString
            txtPurcName3.Text = ReadRow.Item("PurchaserName3").ToString
            txtPurcNric1.Text = ReadRow.Item("PurchaserNRIC1").ToString
            txtPurcNric2.Text = ReadRow.Item("PurchaserNRIC2").ToString
            txtPurcNric3.Text = ReadRow.Item("PurchaserNRIC3").ToString
            txtPurcContactPerson.Text = ReadRow.Item("PurchaserContactPerson").ToString
            txtPurcAddress.Text = ReadRow.Item("PurchaserAddress").ToString
            txtPurcPhone.Text = ReadRow.Item("PurchaserPhone").ToString
            txtPurcMobile.Text = ReadRow.Item("PurchaserMobile").ToString
            txtPurcFax.Text = ReadRow.Item("PurchaserFax").ToString
            txtPurcEmail.Text = ReadRow.Item("PurchaserEmail").ToString
            ddlPurcRefer.SelectedValue = ReadRow.Item("PurchaserReferral").ToString
            'hide vendor if select no
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "checkPurcRefer", "checkPurcRefer();", True)
            txtPurcReferName.Text = ReadRow.Item("PurchaserReferralName").ToString
            txtPurcReferNRIC.Text = ReadRow.Item("PurchaserReferralNRIC").ToString
            txtPurcReferContact.Text = ReadRow.Item("PurchaserReferralContact").ToString
            ddlPurcReferStatus.SelectedValue = ReadRow.Item("PurchaserReferralStatus").ToString
            If ReadRow.Item("PurchaserReferralAmount").ToString = "" Then
                txtPurcReferAmt.Text = "0.00"
            Else
                txtPurcReferAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("PurchaserReferralAmount"))
            End If
            txtPurcSolicitorCompName.Text = ReadRow.Item("PurchaserSolicitorCompany").ToString
            txtPurcSolicitorContactPerson.Text = ReadRow.Item("PurchaserSolicitorName").ToString
            txtPurcSolicitorEmail.Text = ReadRow.Item("PurchaserSolicitorEmail").ToString
            txtPurcSolicitorsAddress.Text = ReadRow.Item("PurchaserSolicitorAddress").ToString
            txtPurcSolicitorsPhone.Text = ReadRow.Item("PurchaserSolicitorPhone").ToString
            txtPurcSolicitorsFax.Text = ReadRow.Item("PurchaserSolicitorFax").ToString
            '--Vendor Fee--
            If ReadRow.Item("AgencyFee").ToString = "" Then
                txtVendorAgencyFee.Text = "0.00"
            Else
                txtVendorAgencyFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("AgencyFee"))
            End If
            If ReadRow.Item("GST").ToString = "" Then
                txtVendorGsts.Text = "0.00"
            Else
                txtVendorGsts.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GST"))
            End If
            If ReadRow.Item("GSTPaidBy").ToString = "1" Then
                chkVendorGstPaid.Checked = True
            Else
                chkVendorGstPaid.Checked = False
            End If
            If ReadRow.Item("VendorReferralAmtSum").ToString = "" Then
                lblVendorReferralAmt.Text = "0.00"
            Else
                lblVendorReferralAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("VendorReferralAmtSum"))
            End If
            If ReadRow.Item("ListingFee").ToString = "" Then
                lblListingPercent.Text = "0.00"
            Else
                lblListingPercent.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListingFee"))
            End If
            '--Purchase Fee--
            If ReadRow.Item("DisbursementFee").ToString = "" Then
                txtPurcDisbursement.Text = "0.00"
            Else
                txtPurcDisbursement.Text = String.Format("{0:#,##0.00}", ReadRow.Item("DisbursementFee"))
            End If
            If ReadRow.Item("PurchaserReferralAmtSum").ToString = "" Then
                lblPurcReferralAmt.Text = "0.00"
            Else
                lblPurcReferralAmt.Text = String.Format("{0:#,##0.00}", ReadRow.Item("PurchaserReferralAmtSum"))
            End If
            If ReadRow.Item("TransListType").ToString = "0" Then
                rbtTransactAs.ClearSelection()
            Else
                rbtTransactAs.SelectedValue = ReadRow.Item("TransListType").ToString
            End If
            txtTransactPrice.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TransactedPrice"))
            txtDepositPaid.Text = String.Format("{0:#,##0.00}", ReadRow.Item("Deposit"))
            ddlModeOfPayment.SelectedValue = ReadRow.Item("PaymentType").ToString
            If ReadRow.Item("PaymentDate").ToString = "" Then
                txtPayOn.Text = ""
            Else
                txtPayOn.Text = Format(ReadRow.Item("PaymentDate"), "dd-MMM-yyyy")
            End If
            txtRequisition.Text = ReadRow.Item("Requisition").ToString
            If ReadRow.Item("CoBroke").ToString = "1" Then
                CoBroke.Visible = True
                lblhidCoBrokeId.Text = ReadRow.Item("CoBrokeId").ToString
                lblCoBroke.Text = ReadRow.Item("CoBrokeName").ToString
                lblhidCoBrokeAgencyName.Text = ReadRow.Item("CoBrokeAgencyName").ToString
                lblhidCoBrokePhone.Text = ReadRow.Item("CoBrokePhone").ToString
                lblhidCoBrokeMobile.Text = ReadRow.Item("CoBrokeMobile").ToString
                lblhidCoBrokeFax.Text = ReadRow.Item("CoBrokeFax").ToString
                lblhidCoBrokeEmail.Text = ReadRow.Item("CoBrokeEmail").ToString
            Else
                CoBroke.Visible = False
            End If
            If ReadRow.Item("TotalAgencyFee").ToString = "" Then
                lblTotalAgencyFee.Text = "0.00"
            Else
                lblTotalAgencyFee.Text = String.Format("{0:#,##0.00}", ReadRow.Item("TotalAgencyFee"))
            End If
            If ReadRow.Item("ListerAmt").ToString = "" Then
                lblForLister.Text = "0.00"
            Else
                lblForLister.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListerAmt"))
            End If
            If ReadRow.Item("ReferralAmt").ToString = "" Then
                lblReferral.Text = "0.00"
            Else
                lblReferral.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ReferralAmt"))
            End If
            If ReadRow.Item("GovAmt").ToString = "" Then
                lblForGorv.Text = "0.00"
            Else
                lblForGorv.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GovAmt"))
            End If
            If ReadRow.Item("GrossAmount").ToString = "" Then
                lblGrossAmount.Text = "0.00"
            Else
                lblGrossAmount.Text = String.Format("{0:#,##0.00}", ReadRow.Item("GrossAmount"))
            End If
            If ReadRow.Item("ListingFee").ToString = "" Then
                lblListingPercent.Text = String.Format("{0:#,##0.00}", getListingPercent(objDB))
            Else
                lblListingPercent.Text = String.Format("{0:#,##0.00}", ReadRow.Item("ListingFee"))
            End If
            'lblForCompany.Text = ReadRow.Item("CompanyAmt").ToString
            'lblForTransactor.Text = ReadRow.Item("TransactorAmt").ToString
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "Calculation", "Calculation();", True)
        Next

        objDB.CloseConnection()

    End Sub

    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Try
            objDB.OpenConnection()
            objDB.InitDbTrans()
            objDB.dbVariable.SQLString = "UPDATE AW_SaleTransaction SET " & _
                                        "ListerId = @ListerId, ListDate = @ListDate, " & _
                                        "VendorType=@VendorType, VendorName1=@VendorName1, VendorName2=@VendorName2, VendorName3=@VendorName3, VendorCompany=@VendorCompany, " & _
                                        "VendorNRIC1=@VendorNRIC1, VendorNRIC2=@VendorNRIC2, VendorNRIC3=@VendorNRIC3, VendorCompanyNo=@VendorCompanyNo, " & _
                                        "VendorAddress=@VendorAddress, VendorPhone=@VendorPhone, VendorMobile=@VendorMobile, VendorFax=@VendorFax, " & _
                                        "VendorEmail=@VendorEmail, VendorReferral=@VendorReferral, VendorReferralName=@VendorReferralName, VendorContactPerson=@VendorContactPerson, " & _
                                        "VendorReferralNRIC=@VendorReferralNRIC, VendorReferralContact=@VendorReferralContact, VendorReferralStatus=@VendorReferralStatus, " & _
                                        "VendorReferralAmount=@VendorReferralAmount, VendorReferralAmtSum=@VendorReferralAmtSum, " & _
                                        "AgencyFee=@AgencyFee, GST=@GST, GSTPaidby=@GSTPaidBy, ListingFee=@ListingFee, VendorSolicitorCompany=@VendorSolicitorCompany, " & _
                                        "VendorSolicitorName=@VendorSolicitorName, VendorSolicitorEmail=@VendorSolicitorEmail, VendorSolicitorAddress=@VendorSolicitorAddress, " & _
                                        "VendorSolicitorPhone=@VendorSolicitorPhone, VendorSolicitorFax=@VendorSolicitorFax, PurchaserType=@PurchaserType, PurchaserName1=@PurchaserName1, " & _
                                        "PurchaserName2=@PurchaserName2, PurchaserName3=@PurchaserName3, PurchaserCompany=@PurchaserCompany, PurchaserNRIC1=@PurchaserNRIC1, " & _
                                        "PurchaserNRIC2=@PurchaserNRIC2, PurchaserNRIC3=@PurchaserNRIC3, PurchaserCompanyNo=@PurchaserCompanyNo, PurchaserAddress=@PurchaserAddress, " & _
                                        "PurchaserPhone=@PurchaserPhone, PurchaserMobile=@PurchaserMobile, PurchaserFax=@PurchaserFax, PurchaserEmail=@PurchaserEmail, " & _
                                        "PurchaserReferral=@PurchaserReferral, PurchaserReferralName=@PurchaserReferralName, PurchaserContactPerson=@PurchaserContactPerson, " & _
                                        "PurchaserReferralNRIC=@PurchaserReferralNRIC, PurchaserReferralContact=@PurchaserReferralContact, PurchaserReferralStatus=@PurchaserReferralStatus, " & _
                                        "PurchaserReferralAmount=@PurchaserReferralAmount, PurchaserReferralAmtSum=@PurchaserReferralAmtSum, DisbursementFee=@DisbursementFee, " & _
                                        "PurchaserSolicitorCompany=@PurchaserSolicitorCompany, PurchaserSolicitorName=@PurchaserSolicitorName, PurchaserSolicitorEmail=@PurchaserSolicitorEmail, " & _
                                        "PurchaserSolicitorAddress=@PurchaserSolicitorAddress, PurchaserSolicitorPhone=@PurchaserSolicitorPhone, PurchaserSolicitorFax=@PurchaserSolicitorFax, " & _
                                        "TransListType=@TransListType, TransactedPrice=@TransactedPrice, Deposit=@Deposit, PaymentType=@PaymentType, PaymentDate=@PaymentDate, " & _
                                        "Requisition=@Requisition, TotalAgencyFee=@TotalAgencyFee, ListerAmt=@ListerAmt, ReferralAmt=@ReferralAmt, GovAmt=@GovAmt, GrossAmount=@GrossAmount, " & _
                                        "UpdateDate=@UpdateDate, UpdateWho=@UpdateWho WHERE TransactionId=@TransId"
            objDB.AddParameter("ListerId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidListerID.Text))
            objDB.AddParameter("ListDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtListDate.Text, "dd-MMM-yyyy", Nothing))
            objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
            objDB.AddParameter("TransListType", Data.SqlDbType.TinyInt, CInt(rbtTransactAs.SelectedValue))
            If txtTransactPrice.Text = "" Then
                objDB.AddParameter("TransactedPrice", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("TransactedPrice", Data.SqlDbType.Decimal, CDbl(txtTransactPrice.Text.Trim))
            End If
            If txtDepositPaid.Text = "" Then
                objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(txtDepositPaid.Text.Trim))
            End If
            If txtPayOn.Text = "" Then
                objDB.AddParameter("PaymentDate", Data.SqlDbType.DateTime, DBNull.Value)
            Else
                objDB.AddParameter("PaymentDate", Data.SqlDbType.DateTime, Date.ParseExact(txtPayOn.Text.Trim, "dd-MMM-yyyy", Nothing))
            End If
            If txtRequisition.Text = "" Then
                objDB.AddParameter("Requisition", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("Requisition", Data.SqlDbType.NChar, txtRequisition.Text.ToUpper.Trim)
            End If
            objDB.AddParameter("PaymentType", Data.SqlDbType.TinyInt, CInt(ddlModeOfPayment.SelectedValue))
            If chkVendorCompany.Checked Then
                objDB.AddParameter("VendorType", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("VendorName1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorName2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorName3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorCompany", Data.SqlDbType.NVarChar, txtVendorCompanyName.Text.ToUpper.Trim)
                objDB.AddParameter("VendorNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorCompanyNo", Data.SqlDbType.NVarChar, txtVendorCompanyNo.Text.ToUpper.Trim)
            Else
                objDB.AddParameter("VendorType", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("VendorName1", Data.SqlDbType.NVarChar, txtVendorName1.Text.ToUpper.Trim)
                objDB.AddParameter("VendorName2", Data.SqlDbType.NVarChar, txtVendorName2.Text.ToUpper.Trim)
                objDB.AddParameter("VendorName3", Data.SqlDbType.NVarChar, txtVendorName3.Text.ToUpper.Trim)
                objDB.AddParameter("VendorCompany", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorNRIC1", Data.SqlDbType.NVarChar, txtVendorNric1.Text.ToUpper.Trim)
                objDB.AddParameter("VendorNRIC2", Data.SqlDbType.NVarChar, txtVendorNric2.Text.ToUpper.Trim)
                objDB.AddParameter("VendorNRIC3", Data.SqlDbType.NVarChar, txtVendorNric3.Text.ToUpper.Trim)
                objDB.AddParameter("VendorCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtVendorContactPerson.Text = "" Then
                objDB.AddParameter("VendorContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorContactPerson", Data.SqlDbType.NVarChar, txtVendorContactPerson.Text.ToUpper.Trim)
            End If
            If txtVendorAddress.Text = "" Then
                objDB.AddParameter("VendorAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorAddress", Data.SqlDbType.NVarChar, txtVendorAddress.Text.ToUpper.Trim)
            End If
            If txtVendorPhone.Text = "" Then
                objDB.AddParameter("VendorPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorPhone", Data.SqlDbType.NVarChar, txtVendorPhone.Text.ToUpper.Trim)
            End If
            If txtVendorMobile.Text = "" Then
                objDB.AddParameter("VendorMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorMobile", Data.SqlDbType.NVarChar, txtVendorMobile.Text.ToUpper.Trim)
            End If
            If txtVendorFax.Text = "" Then
                objDB.AddParameter("VendorFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorFax", Data.SqlDbType.NVarChar, txtVendorFax.Text.ToUpper.Trim)
            End If
            If txtVendorEmail.Text = "" Then
                objDB.AddParameter("VendorEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorEmail", Data.SqlDbType.NVarChar, txtVendorEmail.Text.ToUpper.Trim)
            End If
            If ddlVendorRefer.SelectedValue = "1" Then
                objDB.AddParameter("VendorReferral", Data.SqlDbType.TinyInt, 1)
                If txtVendorReferName.Text = "" Then
                    objDB.AddParameter("VendorReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("VendorReferralName", Data.SqlDbType.NVarChar, txtVendorReferName.Text.ToUpper.Trim)
                End If
                If txtVendorReferNRIC.Text = "" Then
                    objDB.AddParameter("VendorReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("VendorReferralNRIC", Data.SqlDbType.NVarChar, txtVendorReferNRIC.Text.ToUpper.Trim)
                End If
                If txtVendorReferContact.Text = "" Then
                    objDB.AddParameter("VendorReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("VendorReferralContact", Data.SqlDbType.NVarChar, txtVendorReferContact.Text.ToUpper.Trim)
                End If
                objDB.AddParameter("VendorReferralStatus", Data.SqlDbType.TinyInt, ddlVendorReferStatus.SelectedValue)
                If txtVendorReferAmt.Text = "" Then
                    objDB.AddParameter("VendorReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                Else
                    objDB.AddParameter("VendorReferralAmount", Data.SqlDbType.Decimal, CDbl(txtVendorReferAmt.Text.Trim))
                End If
            Else
                objDB.AddParameter("VendorReferral", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("VendorReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("VendorReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                objDB.AddParameter("VendorReferralStatus", Data.SqlDbType.TinyInt, ddlVendorReferStatus.SelectedValue)
            End If
            If txtVendorSolicitorCompName.Text = "" Then
                objDB.AddParameter("VendorSolicitorCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSolicitorCompany", Data.SqlDbType.NVarChar, txtVendorSolicitorCompName.Text.ToUpper.Trim)
            End If
            If txtVendorSolicitorContactPerson.Text = "" Then
                objDB.AddParameter("VendorSolicitorName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSolicitorName", Data.SqlDbType.NVarChar, txtVendorSolicitorContactPerson.Text.ToUpper.Trim)
            End If
            If txtVendorSolicitorEmail.Text = "" Then
                objDB.AddParameter("VendorSolicitorEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSolicitorEmail", Data.SqlDbType.NVarChar, txtVendorSolicitorEmail.Text.ToUpper.Trim)
            End If
            If txtVendorSolicitorsAddress.Text = "" Then
                objDB.AddParameter("VendorSolicitorAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSolicitorAddress", Data.SqlDbType.NVarChar, txtVendorSolicitorsAddress.Text.ToUpper.Trim)
            End If
            If txtVendorSolicitorsPhone.Text = "" Then
                objDB.AddParameter("VendorSolicitorPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSolicitorPhone", Data.SqlDbType.NVarChar, txtVendorSolicitorsPhone.Text.ToUpper.Trim)
            End If
            If txtVendorSolicitorsFax.Text = "" Then
                objDB.AddParameter("VendorSolicitorFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorSolicitorFax", Data.SqlDbType.NVarChar, txtVendorSolicitorsFax.Text.ToUpper.Trim)
            End If
            If chkPurcCompany.Checked Then
                objDB.AddParameter("PurchaserType", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("PurchaserName1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserName2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserName3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserCompany", Data.SqlDbType.NVarChar, txtPurcCompanyName.Text.ToUpper.Trim)
                objDB.AddParameter("PurchaserNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserCompanyNo", Data.SqlDbType.NVarChar, txtPurcCompanyNo.Text.ToUpper.Trim)
            Else
                objDB.AddParameter("PurchaserType", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("PurchaserName1", Data.SqlDbType.NVarChar, txtPurcName1.Text.ToUpper.Trim)
                objDB.AddParameter("PurchaserName2", Data.SqlDbType.NVarChar, txtPurcName2.Text.ToUpper.Trim)
                objDB.AddParameter("PurchaserName3", Data.SqlDbType.NVarChar, txtPurcName3.Text.ToUpper.Trim)
                objDB.AddParameter("PurchaserCompany", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserNRIC1", Data.SqlDbType.NVarChar, txtPurcNric1.Text.ToUpper.Trim)
                objDB.AddParameter("PurchaserNRIC2", Data.SqlDbType.NVarChar, txtPurcNric2.Text.ToUpper.Trim)
                objDB.AddParameter("PurchaserNRIC3", Data.SqlDbType.NVarChar, txtPurcNric3.Text.ToUpper.Trim)
                objDB.AddParameter("PurchaserCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
            End If
            If txtPurcContactPerson.Text = "" Then
                objDB.AddParameter("PurchaserContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserContactPerson", Data.SqlDbType.NVarChar, txtPurcContactPerson.Text.ToUpper.Trim)
            End If
            If txtPurcAddress.Text = "" Then
                objDB.AddParameter("PurchaserAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserAddress", Data.SqlDbType.NVarChar, txtPurcAddress.Text.ToUpper.Trim)
            End If
            If txtPurcPhone.Text = "" Then
                objDB.AddParameter("PurchaserPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserPhone", Data.SqlDbType.NVarChar, txtPurcPhone.Text.ToUpper.Trim)
            End If
            If txtPurcMobile.Text = "" Then
                objDB.AddParameter("PurchaserMobile", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserMobile", Data.SqlDbType.NVarChar, txtPurcMobile.Text.ToUpper.Trim)
            End If
            If txtPurcFax.Text = "" Then
                objDB.AddParameter("PurchaserFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserFax", Data.SqlDbType.NVarChar, txtPurcFax.Text.ToUpper.Trim)
            End If
            If txtPurcEmail.Text = "" Then
                objDB.AddParameter("PurchaserEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserEmail", Data.SqlDbType.NVarChar, txtPurcEmail.Text.ToUpper.Trim)
            End If
            If ddlPurcRefer.SelectedValue = "1" Then
                objDB.AddParameter("PurchaserReferral", Data.SqlDbType.TinyInt, 1)
                If txtPurcReferName.Text = "" Then
                    objDB.AddParameter("PurchaserReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("PurchaserReferralName", Data.SqlDbType.NVarChar, txtPurcReferName.Text.ToUpper.Trim)
                End If
                If txtPurcReferNRIC.Text = "" Then
                    objDB.AddParameter("PurchaserReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("PurchaserReferralNRIC", Data.SqlDbType.NVarChar, txtPurcReferNRIC.Text.ToUpper.Trim)
                End If
                If txtPurcReferContact.Text = "" Then
                    objDB.AddParameter("PurchaserReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                Else
                    objDB.AddParameter("PurchaserReferralContact", Data.SqlDbType.NVarChar, txtPurcReferContact.Text.ToUpper.Trim)
                End If
                objDB.AddParameter("PurchaserReferralStatus", Data.SqlDbType.TinyInt, ddlPurcReferStatus.SelectedValue)
                If txtPurcReferAmt.Text = "" Then
                    objDB.AddParameter("PurchaserReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                Else
                    objDB.AddParameter("PurchaserReferralAmount", Data.SqlDbType.Decimal, CDbl(txtPurcReferAmt.Text.Trim))
                End If
            Else
                objDB.AddParameter("PurchaserReferral", Data.SqlDbType.TinyInt, 0)
                objDB.AddParameter("PurchaserReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
                objDB.AddParameter("PurchaserReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
                objDB.AddParameter("PurchaserReferralStatus", Data.SqlDbType.TinyInt, ddlPurcReferStatus.SelectedValue)
            End If
            If txtPurcSolicitorCompName.Text = "" Then
                objDB.AddParameter("PurchaserSolicitorCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserSolicitorCompany", Data.SqlDbType.NVarChar, txtPurcSolicitorCompName.Text.ToUpper.Trim)
            End If
            If txtPurcSolicitorContactPerson.Text = "" Then
                objDB.AddParameter("PurchaserSolicitorName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserSolicitorName", Data.SqlDbType.NVarChar, txtPurcSolicitorContactPerson.Text.ToUpper.Trim)
            End If
            If txtPurcSolicitorEmail.Text = "" Then
                objDB.AddParameter("PurchaserSolicitorEmail", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserSolicitorEmail", Data.SqlDbType.NVarChar, txtPurcSolicitorEmail.Text.ToUpper.Trim)
            End If
            If txtPurcSolicitorsAddress.Text = "" Then
                objDB.AddParameter("PurchaserSolicitorAddress", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserSolicitorAddress", Data.SqlDbType.NVarChar, txtPurcSolicitorsAddress.Text.ToUpper.Trim)
            End If
            If txtPurcSolicitorsPhone.Text = "" Then
                objDB.AddParameter("PurchaserSolicitorPhone", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserSolicitorPhone", Data.SqlDbType.NVarChar, txtPurcSolicitorsPhone.Text.ToUpper.Trim)
            End If
            If txtPurcSolicitorsFax.Text = "" Then
                objDB.AddParameter("PurchaserSolicitorFax", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserSolicitorFax", Data.SqlDbType.NVarChar, txtPurcSolicitorsFax.Text.ToUpper.Trim)
            End If
            'Fee
            If txtVendorAgencyFee.Text = "" Then
                objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(txtVendorAgencyFee.Text.Trim))
            End If
            If txtVendorGsts.Text = "" Then
                objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(txtVendorGsts.Text.Trim))
            End If
            If chkVendorGstPaid.Checked Then
                objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 1)
            Else
                objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 0)
            End If
            If lblListingPercent.Text = "" Then
                objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(lblListingPercent.Text.Trim))
            End If
            If lblVendorReferralAmt.Text = "" Then
                objDB.AddParameter("VendorReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("VendorReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblVendorReferralAmt.Text.Trim))
            End If
            If txtPurcDisbursement.Text = "" Then
                objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(txtPurcDisbursement.Text.Trim))
            End If
            If lblPurcReferralAmt.Text = "" Then
                objDB.AddParameter("PurchaserReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("PurchaserReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblPurcReferralAmt.Text.Trim))
            End If
            If lblTotalAgencyFee.Text = "" Then
                objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(lblTotalAgencyFee.Text.Trim))
            End If
            If lblForLister.Text = "" Then
                objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(lblForLister.Text.Trim))
            End If
            If lblReferral.Text = "" Then
                objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(lblReferral.Text.Trim))
            End If
            If lblForGorv.Text = "" Then
                objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(lblForGorv.Text.Trim))
            End If
            'If lblForCompany.Text = "" Then
            '    objDB.AddParameter("CompanyAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            'Else
            '    objDB.AddParameter("CompanyAmt", Data.SqlDbType.Decimal, CDbl(lblForCompany.Text.Trim))
            'End If
            'If lblForTransactor.Text = "" Then
            '    objDB.AddParameter("TransactorAmt", Data.SqlDbType.Decimal, CDbl(0.0))
            'Else
            '    objDB.AddParameter("TransactorAmt", Data.SqlDbType.Decimal, CDbl(lblForTransactor.Text.Trim))
            'End If
            If lblGrossAmount.Text = "" Then
                objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(lblGrossAmount.Text.Trim))
            End If
            objDB.AddParameter("UpdateDate", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("UpdateWho", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text.Trim))
            objDB.ExecuteQuery()
            Dim strOpenFileRef As String = String.Empty
            If txtOpenFileNumber.Text = "" Then
                getOpenFormatNumber(objDB, strOpenFileRef, New Guid(lblhidTransactorId.Text.Trim), New Guid(lblhidListerID.Text.Trim), "S", New Guid(lblStaffUID.Text))
                objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, strOpenFileRef)
                objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
                objDB.dbVariable.SQLString = "UPDATE AW_SaleTransaction SET " & _
                                    "OpenFileRef=@OpenFileRef, Status=@Status " & _
                                    "WHERE TransactionId=@TransId"
            Else
                strOpenFileRef = txtOpenFileNumber.Text.ToUpper.Trim
                objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, txtOpenFileNumber.Text.ToUpper.Trim)
                objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
                objDB.dbVariable.SQLString = "UPDATE AW_SaleTransaction SET " & _
                                    "OpenFileRef=@OpenFileRef " & _
                                    "WHERE TransactionId=@TransId"
            End If
            objDB.ExecuteQuery()
            objDB.ClearParameter()
            objDB.AddParameter("OpenFileRef", Data.SqlDbType.NVarChar, strOpenFileRef)
            InsertTrans_Old(objDB)
            objDB.ClearParameter()
            InsertUpdateContactVendor(objDB)
            InsertUpdateContactPurc(objDB)
            objDB.DbTransCommit()
            objDB.CloseConnection()
            Session.Add("entry", txtPremiseName.Text.Trim)
            Response.Redirect("Translist.aspx", False)
        Catch ex As Exception
            objDB.DbTransRollback()
            If objDB.dbVariable.objConn.State = Data.ConnectionState.Open Then
                objDB.CloseConnection()
            End If
            lblMsgError.Text = ex.Message
            divError.Visible = True
        End Try
       
    End Sub

    Protected Sub rbtTransactAs_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rbtTransactAs.SelectedIndexChanged
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        Dim TempDT As New Data.DataTable

        objDB.OpenConnection()
        Select Case rbtTransactAs.SelectedValue
            Case "1"  '--SR
                objDB.dbVariable.SQLString = "SELECT SRCreateDate as CreateDate, SListerId as ListerId, l.Name as Lister, l.ListingPercent FROM AW_Property p INNER JOIN AW_SaleTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.SListerId = l.StaffId WHERE TransactionId = @TransId"
            Case "2" '--SC
                objDB.dbVariable.SQLString = "SELECT SCCreateDate as CreateDate, SListerId as ListerId, l.Name as Lister, l.ListingPercent FROM AW_Property p INNER JOIN AW_SaleTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.SListerId = l.StaffId WHERE TransactionId = @TransId"
            Case "3" '--SL
                objDB.dbVariable.SQLString = "SELECT SLCreateDate as CreateDate, SListerId as ListerId, l.Name as Lister, l.ListingPercent FROM AW_Property p INNER JOIN AW_SaleTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.SListerId = l.StaffId WHERE TransactionId = @TransId"
            Case "4" '--SI
                objDB.dbVariable.SQLString = "SELECT SICreateDate as CreateDate, SListerId as ListerId, l.Name as Lister, l.ListingPercent FROM AW_Property p INNER JOIN AW_SaleTransaction s " & _
                                    "ON p.PropertyId = s.PropertyId INNER JOIN AW_Staff l ON p.SListerId = l.StaffId WHERE TransactionId = @TransId"
        End Select
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text.Trim))
        objDB.FillData(TempDT, "AW_SaleTransaction", Database.SQLCommandType.NormalString)

        For Each row As Data.DataRow In TempDT.Rows
            txtListDate.Text = Format(row.Item("CreateDate"), "dd-MMM-yyyy")
            txtLister.Text = row.Item("Lister").ToString
            lblhidListerID.Text = row.Item("ListerId").ToString
        Next
        'lblListingPercent.Text = getListingPercent(objDB)
        objDB.CloseConnection()
    End Sub

    Private Function getListingPercent(ByRef ObjDB As Database) As String
        Dim ListingPercentDT As New Data.DataTable
        Dim ListingPercent As String = "0.00"

        ObjDB.dbVariable.SQLString = "SELECT ListingPercent FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidListerID.Text.Trim))
        ObjDB.FillData(ListingPercentDT, "ListingPercent", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In ListingPercentDT.Rows
            If ReadRow.Item("ListingPercent").ToString = "" Then
                ListingPercent = "0.00"
            Else
                ListingPercent = ReadRow.Item("ListingPercent").ToString
            End If
        Next
        Return ListingPercent
    End Function

    ''' <summary>
    ''' This function will Get All the Formatted Number
    ''' </summary>
    ''' <param name="ObjDB">The Database object used</param>
    ''' <param name="OpenFormat">This will return the Format Number just Pass a Variable</param>
    ''' <param name="TransactorUid">The GUID variable of the Transactor</param>
    ''' <param name="ListerUid">The GUID variable of the Lister</param>
    ''' <param name="ListType">Please pass in only R or S</param>
    ''' <returns>It Returns nothing but it uses the ByRef</returns>
    ''' <remarks></remarks>
    Private Function getOpenFormatNumber(ByRef ObjDB As Database, ByRef OpenFormat As String, ByVal TransactorUid As Guid, ByVal ListerUid As Guid, ByVal ListType As String, ByVal LoginUid As Guid) As Integer

        Dim InvoiceDT As New Data.DataTable
        Dim ListerDT As New Data.DataTable
        Dim TransactorDT As New Data.DataTable
        Dim RunningNoDt As New Data.DataTable
        Dim OpenFileRunningNo As Integer = 0
        Dim TransactorInitial As String = ""
        Dim ListerInitial As String = ""
        Dim ListerName As String = ""
        Dim CompanyName As String = ""
        Dim CompanyInitial As String = ""
        Dim LoginInitial As String = "" 'Added by : Daniel Date:19-July-2011 Purpose:To include Login inital
        Dim LoginInitialDT As New Data.DataTable

        'Get All Information Before Proceesing
        'Get Transactor Initial
        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, TransactorUid)
        ObjDB.FillData(TransactorDT, "Transactor", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In TransactorDT.Rows
            TransactorInitial = ReadRow.Item("Initial").ToString
        Next

        ObjDB.ClearParameter()
        ObjDB.dbVariable.SQLString = "SELECT Initial FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, LoginUid)
        ObjDB.FillData(LoginInitialDT, "LoginInitial", Database.SQLCommandType.NormalString)

        For Each readrow As Data.DataRow In LoginInitialDT.Rows
            LoginInitial = readrow.Item("Initial").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT Initial,Name FROM AW_Staff WHERE StaffId=@StaffId"
        ObjDB.ClearParameter()
        ObjDB.AddParameter("StaffId", Data.SqlDbType.UniqueIdentifier, ListerUid)
        ObjDB.FillData(ListerDT, "Lister", Database.SQLCommandType.NormalString)

        For Each ReadRow As Data.DataRow In ListerDT.Rows
            ListerInitial = ReadRow.Item("Initial").ToString
            ListerName = ReadRow.Item("Name").ToString
        Next

        ObjDB.dbVariable.SQLString = "SELECT CurrentNo,RunType FROM aw_runningNo WITH (TABLOCKX) WHERE RunType='O' "
        ObjDB.FillData(RunningNoDt, "RunningNo", Database.SQLCommandType.NormalString)

        'Begin Updating Current Running No
        ObjDB.dbVariable.SQLString = "UPDATE aw_runningNo SET CurrentNo=CurrentNo+1 WHERE RunType='O'"
        ObjDB.ExecuteQuery()

        For Each ReadRow As Data.DataRow In RunningNoDt.Rows
            If ReadRow.Item("RunType").ToString = "O" Then
                OpenFileRunningNo = ReadRow.Item("CurrentNo")
            End If
        Next

        ObjDB.dbVariable.SQLString = "SELECT OpenFormat,CompanyName,CompanyInitial FROM AW_Setting"
        ObjDB.FillData(InvoiceDT, "OpenFormat", Database.SQLCommandType.NormalString)

        Dim OpenFormatString As String()

        For Each ReadRow As Data.DataRow In InvoiceDT.Rows
            OpenFormatString = ReadRow.Item("OpenFormat").ToString.Split(";")
            CompanyInitial = ReadRow.Item("CompanyInitial").ToString
            CompanyName = ReadRow.Item("CompanyName").ToString
        Next


        Dim strOpenFormat As String = String.Empty
        If OpenFormatString.Count > 0 Then
            For Each Format As String In OpenFormatString
                Select Case Format.Trim
                    Case "tInit"
                        strOpenFormat = strOpenFormat & TransactorInitial
                    Case "lName"
                        strOpenFormat = strOpenFormat & ListerName
                    Case "lInit"
                        strOpenFormat = strOpenFormat & ListerInitial
                    Case "cName"
                        strOpenFormat = strOpenFormat & CompanyName
                    Case "cInit"
                        strOpenFormat = strOpenFormat & CompanyInitial
                    Case "rNumber"
                        strOpenFormat = strOpenFormat & OpenFileRunningNo
                    Case "dDate1"
                        strOpenFormat = strOpenFormat & Now.ToString("dd/MM")
                    Case "dDate2"
                        strOpenFormat = strOpenFormat & Now.ToString("dd/MM/yyyy")
                    Case "LoginInit"
                        strOpenFormat = strOpenFormat & LoginInitial
                    Case "lType"
                        If ListType = "S" Then
                            strOpenFormat = strOpenFormat & "S"
                        Else
                            strOpenFormat = strOpenFormat & "R"
                        End If
                    Case "dash"
                        strOpenFormat = strOpenFormat & "-"
                    Case "slash"
                        strOpenFormat = strOpenFormat & "/"
                    Case "empty"
                        strOpenFormat = strOpenFormat & ""
                End Select

            Next
        End If

        OpenFormat = strOpenFormat
        Return 0
    End Function

    Protected Sub btnGetListingFee_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetListingFee.Click
        Dim objDB As New Database(AppSettings("datasource"), AppSettings("database"), AppSettings("username"), AppSettings("password"), AppSettings("timeout"), AppSettings("pooling"))
        objDB.OpenConnection()
        lblListingPercent.Text = getListingPercent(objDB)
        objDB.CloseConnection()
        'Calculation
        Calculation()
    End Sub

    Private Sub Calculation()
        Dim VendorReferralAmt, PurcReferralAmt, VendorAgencyFee As Decimal
        Dim GST, TotalAgencyFee, referral, Lister, GrossAmount As Decimal
        'Referral Summary
        If ddlVendorReferStatus.SelectedValue = "0" And ddlPurcReferStatus.SelectedValue = "1" Then
            VendorReferralAmt = CDbl(txtVendorReferAmt.Text) + CDbl(txtPurcReferAmt.Text)
            PurcReferralAmt = 0
            lblVendorReferralAmt.Text = String.Format("{0:#,##0.00}", VendorReferralAmt)
            lblPurcReferralAmt.Text = String.Format("{0:#,##0.00}", PurcReferralAmt)
        ElseIf ddlVendorReferStatus.SelectedValue = "1" And ddlPurcReferStatus.SelectedValue = "0" Then
            PurcReferralAmt = CDbl(txtVendorReferAmt.Text) + CDbl(txtPurcReferAmt.Text)
            VendorReferralAmt = 0
            lblVendorReferralAmt.Text = String.Format("{0:#,##0.00}", VendorReferralAmt)
            lblPurcReferralAmt.Text = String.Format("{0:#,##0.00}", PurcReferralAmt)
        ElseIf ddlVendorReferStatus.SelectedValue = "1" And ddlPurcReferStatus.SelectedValue = "1" Then
            VendorReferralAmt = CDbl(txtPurcReferAmt.Text)
            PurcReferralAmt = CDbl(txtVendorReferAmt.Text)
            lblVendorReferralAmt.Text = String.Format("{0:#,##0.00}", VendorReferralAmt)
            lblPurcReferralAmt.Text = String.Format("{0:#,##0.00}", PurcReferralAmt)
        Else
            VendorReferralAmt = CDbl(txtVendorReferAmt.Text)
            PurcReferralAmt = CDbl(txtPurcReferAmt.Text)
            lblVendorReferralAmt.Text = String.Format("{0:#,##0.00}", VendorReferralAmt)
            lblPurcReferralAmt.Text = String.Format("{0:#,##0.00}", PurcReferralAmt)
        End If
        'Gov
        GST = (CDbl(txtVendorGsts.Text) / 100) * CDbl(txtVendorAgencyFee.Text)
        lblForGorv.Text = String.Format("{0:#,##0.00}", GST)
        'Total Agency Fee
        If chkVendorGstPaid.Checked Then
            TotalAgencyFee = CDbl(txtVendorAgencyFee.Text) + CDbl(txtPurcDisbursement.Text)
            lblTotalAgencyFee.Text = String.Format("{0:#,##0.00}", TotalAgencyFee)
        Else
            TotalAgencyFee = CDbl(txtVendorAgencyFee.Text) + CDbl(txtPurcDisbursement.Text) - CDbl(GST)
            lblTotalAgencyFee.Text = String.Format("{0:#,##0.00}", TotalAgencyFee)
        End If
        'For Referral
        referral = VendorReferralAmt + PurcReferralAmt
        lblReferral.Text = String.Format("{0:#,##0.00}", referral)
        'For Lister
        'Edited by minginn @ 16/11/2011 - To only take Vendor AgencyFee and Vendor Referrral in calculation of lister fee
        'Lister = ((TotalAgencyFee - referral) * (CDbl(lblListingPercent.Text) / 100))
        'lblForLister.Text = String.Format("{0:#,##0.00}", Lister)
        If chkVendorGstPaid.Checked Then
            VendorAgencyFee = CDbl(txtVendorAgencyFee.Text)
        Else
            VendorAgencyFee = CDbl(txtVendorAgencyFee.Text) - CDbl(GST)
        End If
        Lister = ((VendorAgencyFee - VendorReferralAmt) * (CDbl(lblListingPercent.Text) / 100))
        lblForLister.Text = String.Format("{0:#,##0.00}", Lister)
        'For Gross Amount
        GrossAmount = TotalAgencyFee - referral
        lblGrossAmount.Text = String.Format("{0:#,##0.00}", GrossAmount)
    End Sub

    Private Sub InsertUpdateContactVendor(ByRef objDB As Database)
        If txtVendorMobile.Text <> String.Empty Then
            Dim strSQLCont As String = String.Empty
            Dim TempDT As New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT ContactId, Mobile FROM AW_Contact WHERE Mobile=@Mobile AND StatusDelete=0"
            objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtVendorMobile.Text.Trim.ToUpper)
            objDB.FillData(TempDT, "AW_Contact", Database.SQLCommandType.NormalString)
            If TempDT.Rows.Count > 0 Then
                'Update
                objDB.dbVariable.SQLString = "UPDATE AW_Contact SET ProspectiveType=@ProspectiveType, Name=@Name, " & _
                                            "Mobile=@Mobile" & strSQLCont & " WHERE Mobile=@Mobile"
                If txtVendorPhone.Text <> String.Empty Then
                    strSQLCont += ", Phone=@Phone"
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtVendorPhone.Text.Trim.ToUpper)
                End If
                If txtVendorFax.Text <> String.Empty Then
                    strSQLCont += ", Fax=@Fax"
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtVendorFax.Text.Trim.ToUpper)
                End If
                If txtVendorEmail.Text <> String.Empty Then
                    strSQLCont += ", Email=@Email"
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtVendorEmail.Text.Trim.ToUpper)
                End If
                If txtVendorAddress.Text <> String.Empty Then
                    strSQLCont += ", Address=@Address"
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtVendorAddress.Text.Trim.ToUpper)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 3)
                objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtVendorContactPerson.Text.Trim.ToUpper)
                objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtVendorMobile.Text.Trim.ToUpper)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            Else
                'Insert
                objDB.dbVariable.SQLString = "INSERT INTO AW_Contact(ContactId,Name, ProspectiveType, Mobile, Phone, " & _
                "Fax, Email, Address, CreateDate, StatusDelete) Values(@ContactId, @Name, @ProspectiveType, @Mobile, " & _
                "@Phone, @Fax, @Email, @Address, @CreateDate, @StatusDelete) "
                objDB.AddParameter("ContactId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
                If txtVendorPhone.Text <> String.Empty Then
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtVendorPhone.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtVendorFax.Text <> String.Empty Then
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtVendorFax.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtVendorEmail.Text <> String.Empty Then
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtVendorEmail.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtVendorAddress.Text <> String.Empty Then
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtVendorAddress.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 3)
                If txtVendorContactPerson.Text <> String.Empty Then
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtVendorContactPerson.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtVendorMobile.Text <> String.Empty Then
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtVendorMobile.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            End If
        End If
    End Sub

    Private Sub InsertUpdateContactPurc(ByRef objDB As Database)
        If txtPurcMobile.Text <> String.Empty Then
            Dim strSQLCont As String = String.Empty
            Dim TempDT As New Data.DataTable
            objDB.dbVariable.SQLString = "SELECT ContactId, Mobile FROM AW_Contact WHERE Mobile=@Mobile AND StatusDelete=0"
            objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtPurcMobile.Text.Trim.ToUpper)
            objDB.FillData(TempDT, "AW_Contact", Database.SQLCommandType.NormalString)
            If TempDT.Rows.Count > 0 Then
                'Update
                objDB.dbVariable.SQLString = "UPDATE AW_Contact SET ProspectiveType=@ProspectiveType, Name=@Name, " & _
                                            "Mobile=@Mobile" & strSQLCont & " WHERE Mobile=@Mobile"
                If txtPurcPhone.Text <> String.Empty Then
                    strSQLCont += ", Phone=@Phone"
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtPurcPhone.Text.Trim.ToUpper)
                End If
                If txtPurcFax.Text <> String.Empty Then
                    strSQLCont += ", Fax=@Fax"
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtPurcFax.Text.Trim.ToUpper)
                End If
                If txtPurcEmail.Text <> String.Empty Then
                    strSQLCont += ", Email=@Email"
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtPurcEmail.Text.Trim.ToUpper)
                End If
                If txtPurcAddress.Text <> String.Empty Then
                    strSQLCont += ", Address=@Address"
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtPurcAddress.Text.Trim.ToUpper)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 1)
                objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtPurcContactPerson.Text.Trim.ToUpper)
                objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtPurcMobile.Text.Trim.ToUpper)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            Else
                'Insert
                objDB.dbVariable.SQLString = "INSERT INTO AW_Contact(ContactId,Name, ProspectiveType, Mobile, Phone, " & _
                "Fax, Email, Address, CreateDate, StatusDelete) Values(@ContactId, @Name, @ProspectiveType, @Mobile, " & _
                "@Phone, @Fax, @Email, @Address, @CreateDate, @StatusDelete) "
                objDB.AddParameter("ContactId", Data.SqlDbType.UniqueIdentifier, Guid.NewGuid)
                If txtPurcPhone.Text <> String.Empty Then
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, txtPurcPhone.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Phone", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtPurcFax.Text <> String.Empty Then
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, txtPurcFax.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Fax", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtPurcEmail.Text <> String.Empty Then
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, txtPurcEmail.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Email", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtPurcAddress.Text <> String.Empty Then
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, txtPurcAddress.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Address", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("ProspectiveType", Data.SqlDbType.TinyInt, 1)
                If txtPurcContactPerson.Text <> String.Empty Then
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, txtPurcContactPerson.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Name", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                If txtPurcMobile.Text <> String.Empty Then
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, txtPurcMobile.Text.Trim.ToUpper)
                Else
                    objDB.AddParameter("Mobile", Data.SqlDbType.NVarChar, DBNull.Value)
                End If
                objDB.AddParameter("CreateDate", Data.SqlDbType.DateTime, Now())
                objDB.AddParameter("StatusDelete", Data.SqlDbType.TinyInt, 0)
                objDB.ExecuteQuery()
                objDB.ClearParameter()
            End If
        End If
    End Sub

    Private Sub InsertTrans_Old(ByVal objDB As Database)
        Dim OId As Guid
        If Not Session("Oid") Is Nothing Then
            OId = New Guid(Session("Oid").ToString)
            Session.Remove("Oid")
            'update
            objDB.dbVariable.SQLString = "UPDATE " + AppSettings("logdatasource").ToString() + ".dbo.AW_SaleTransaction SET " & _
                                        "ListerId = @ListerId, ListDate = @ListDate, OpenFileRef=@OpenFileRef, Status=@Status, " & _
                                        "VendorType=@VendorType, VendorName1=@VendorName1, VendorName2=@VendorName2, VendorName3=@VendorName3, VendorCompany=@VendorCompany, " & _
                                        "VendorNRIC1=@VendorNRIC1, VendorNRIC2=@VendorNRIC2, VendorNRIC3=@VendorNRIC3, VendorCompanyNo=@VendorCompanyNo, " & _
                                        "VendorAddress=@VendorAddress, VendorPhone=@VendorPhone, VendorMobile=@VendorMobile, VendorFax=@VendorFax, " & _
                                        "VendorEmail=@VendorEmail, VendorReferral=@VendorReferral, VendorReferralName=@VendorReferralName, VendorContactPerson=@VendorContactPerson, " & _
                                        "VendorReferralNRIC=@VendorReferralNRIC, VendorReferralContact=@VendorReferralContact, VendorReferralStatus=@VendorReferralStatus, " & _
                                        "VendorReferralAmount=@VendorReferralAmount, VendorReferralAmtSum=@VendorReferralAmtSum, " & _
                                        "AgencyFee=@AgencyFee, GST=@GST, GSTPaidby=@GSTPaidBy, ListingFee=@ListingFee, VendorSolicitorCompany=@VendorSolicitorCompany, " & _
                                        "VendorSolicitorName=@VendorSolicitorName, VendorSolicitorEmail=@VendorSolicitorEmail, VendorSolicitorAddress=@VendorSolicitorAddress, " & _
                                        "VendorSolicitorPhone=@VendorSolicitorPhone, VendorSolicitorFax=@VendorSolicitorFax, PurchaserType=@PurchaserType, PurchaserName1=@PurchaserName1, " & _
                                        "PurchaserName2=@PurchaserName2, PurchaserName3=@PurchaserName3, PurchaserCompany=@PurchaserCompany, PurchaserNRIC1=@PurchaserNRIC1, " & _
                                        "PurchaserNRIC2=@PurchaserNRIC2, PurchaserNRIC3=@PurchaserNRIC3, PurchaserCompanyNo=@PurchaserCompanyNo, PurchaserAddress=@PurchaserAddress, " & _
                                        "PurchaserPhone=@PurchaserPhone, PurchaserMobile=@PurchaserMobile, PurchaserFax=@PurchaserFax, PurchaserEmail=@PurchaserEmail, " & _
                                        "PurchaserReferral=@PurchaserReferral, PurchaserReferralName=@PurchaserReferralName, PurchaserContactPerson=@PurchaserContactPerson, " & _
                                        "PurchaserReferralNRIC=@PurchaserReferralNRIC, PurchaserReferralContact=@PurchaserReferralContact, PurchaserReferralStatus=@PurchaserReferralStatus, " & _
                                        "PurchaserReferralAmount=@PurchaserReferralAmount, PurchaserReferralAmtSum=@PurchaserReferralAmtSum, DisbursementFee=@DisbursementFee, " & _
                                        "PurchaserSolicitorCompany=@PurchaserSolicitorCompany, PurchaserSolicitorName=@PurchaserSolicitorName, PurchaserSolicitorEmail=@PurchaserSolicitorEmail, " & _
                                        "PurchaserSolicitorAddress=@PurchaserSolicitorAddress, PurchaserSolicitorPhone=@PurchaserSolicitorPhone, PurchaserSolicitorFax=@PurchaserSolicitorFax, " & _
                                        "TransListType=@TransListType, TransactedPrice=@TransactedPrice, Deposit=@Deposit, PaymentType=@PaymentType, PaymentDate=@PaymentDate, " & _
                                        "Requisition=@Requisition, TotalAgencyFee=@TotalAgencyFee, ListerAmt=@ListerAmt, ReferralAmt=@ReferralAmt, GovAmt=@GovAmt, GrossAmount=@GrossAmount " & _
                                        "WHERE OId=@OId"
            objDB.AddParameter("Status", Data.SqlDbType.TinyInt, 1)
        Else
            OId = Guid.NewGuid
            'insert
            objDB.dbVariable.SQLString = "INSERT INTO " + AppSettings("logdatasource").ToString() + ".dbo.AW_SaleTransaction (OId, TransactionId, PropertyId, InvoiceNumber, OpenFileRef, " & _
                                        "CloseFileRef, ListerId, ListDate, VendorType, VendorName1, VendorName2, VendorName3, VendorCompany, " & _
                                        "VendorNRIC1, VendorNRIC2, VendorNRIC3, VendorCompanyNo, VendorContactPerson, VendorAddress, VendorPhone, " & _
                                        "VendorMobile, VendorFax, VendorEmail, VendorReferral, VendorReferralName, VendorReferralNRIC, " & _
                                        "VendorReferralContact, VendorReferralStatus, VendorReferralAmount, VendorReferralAmtSum, AgencyFee, GST, GSTPaidBy, " & _
                                        "ListingFee, VendorSolicitorCompany, VendorSolicitorName, VendorSolicitorEmail, VendorSolicitorAddress, VendorSolicitorPhone, " & _
                                        "VendorSolicitorFax, PurchaserType, PurchaserName1, PurchaserName2, PurchaserName3, PurchaserCompany, PurchaserNRIC1, " & _
                                        "PurchaserNRIC2, PurchaserNRIC3, PurchaserCompanyNo, PurchaserContactPerson, PurchaserAddress, PurchaserPhone, " & _
                                        "PurchaserMobile, PurchaserFax, PurchaserEmail, PurchaserReferral, PurchaserReferralName, PurchaserReferralNRIC, " & _
                                        "PurchaserReferralContact, PurchaserReferralStatus, PurchaserReferralAmount, PurchaserReferralAmtSum, DisbursementFee, " & _
                                        "PurchaserSolicitorCompany, PurchaserSolicitorName, PurchaserSolicitorEmail, PurchaserSolicitorAddress, " & _
                                        "PurchaserSolicitorPhone, PurchaserSolicitorFax, TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, " & _
                                        "TransListType, TransactedPrice, Deposit, PaymentType, PaymentDate, Requisition, CreateDate, UpdateDate, UpdateWho, " & _
                                        "Status, TotalAgencyFee, ListerAmt, ReferralAmt, GovAmt, GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, " & _
                                        "SignCompleteDate, SNPDate, CollectDate, CollectAmt, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, " & _
                                        "UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, UndoGST, UndoGSTPaidBy, UndoListerAmt) SELECT @OId, TransactionId, PropertyId, " & _
                                        "InvoiceNumber, @OpenFileRef, CloseFileRef, @ListerId, @ListDate, @VendorType, @VendorName1, @VendorName2, @VendorName3, " & _
                                        "@VendorCompany, @VendorNRIC1, @VendorNRIC2, @VendorNRIC3, @VendorCompanyNo, @VendorContactPerson, @VendorAddress, " & _
                                        "@VendorPhone, @VendorMobile, @VendorFax, @VendorEmail, @VendorReferral, @VendorReferralName, @VendorReferralNRIC, " & _
                                        "@VendorReferralContact, @VendorReferralStatus, @VendorReferralAmount, @VendorReferralAmtSum, @AgencyFee, @GST, @GSTPaidBy, " & _
                                        "@ListingFee, @VendorSolicitorCompany, @VendorSolicitorName, @VendorSolicitorEmail, @VendorSolicitorAddress, @VendorSolicitorPhone, " & _
                                        "@VendorSolicitorFax, @PurchaserType, @PurchaserName1, @PurchaserName2, @PurchaserName3, @PurchaserCompany, @PurchaserNRIC1, " & _
                                        "@PurchaserNRIC2, @PurchaserNRIC3, @PurchaserCompanyNo, @PurchaserContactPerson, @PurchaserAddress, @PurchaserPhone, " & _
                                        "@PurchaserMobile, @PurchaserFax, @PurchaserEmail, @PurchaserReferral, @PurchaserReferralName, @PurchaserReferralNRIC, " & _
                                        "@PurchaserReferralContact, @PurchaserReferralStatus, @PurchaserReferralAmount, @PurchaserReferralAmtSum, @DisbursementFee, " & _
                                        "@PurchaserSolicitorCompany, @PurchaserSolicitorName, @PurchaserSolicitorEmail, @PurchaserSolicitorAddress, " & _
                                        "@PurchaserSolicitorPhone, @PurchaserSolicitorFax, TransactorId, CoBroke, CoBrokeId, TransactDate, TransactRemark, " & _
                                        "@TransListType, @TransactedPrice, @Deposit, @PaymentType, @PaymentDate, @Requisition, @CreateDateOLD, @UpdateDateOLD, @UpdateWhoOLD, " & _
                                        "Status, @TotalAgencyFee, @ListerAmt, @ReferralAmt, @GovAmt, @GrossAmount, SignDate, SignRemark, SignComplete, SignCompleteBy, " & _
                                        "SignCompleteDate, SNPDate, CollectDate, CollectAmt, CollectComplete, CollectCompleteBy, CollectCompleteDate, UndoDate, " & _
                                        "UndoRemark, UndoAmt, UndoBy, UndoAgencyFee, UndoGST, UndoGSTPaidBy, UndoListerAmt FROM AW_SaleTransaction WHERE TransactionId = @TransId"
            objDB.AddParameter("CreateDateOLD", Data.SqlDbType.DateTime, Now())
            objDB.AddParameter("UpdateDateOLD", Data.SqlDbType.DateTime, DBNull.Value)
            objDB.AddParameter("UpdateWhoOLD", Data.SqlDbType.UniqueIdentifier, New Guid(lblStaffUID.Text))
        End If
       
        objDB.AddParameter("OId", Data.SqlDbType.UniqueIdentifier, OId)

        objDB.AddParameter("ListerId", Data.SqlDbType.UniqueIdentifier, New Guid(lblhidListerID.Text))
        objDB.AddParameter("ListDate", Data.SqlDbType.DateTime, DateTime.ParseExact(txtListDate.Text, "dd-MMM-yyyy", Nothing))
        objDB.AddParameter("TransId", Data.SqlDbType.UniqueIdentifier, New Guid(lblTransUID.Text))
        objDB.AddParameter("TransListType", Data.SqlDbType.TinyInt, CInt(rbtTransactAs.SelectedValue))
        If txtTransactPrice.Text = "" Then
            objDB.AddParameter("TransactedPrice", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("TransactedPrice", Data.SqlDbType.Decimal, CDbl(txtTransactPrice.Text.Trim))
        End If
        If txtDepositPaid.Text = "" Then
            objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("Deposit", Data.SqlDbType.Decimal, CDbl(txtDepositPaid.Text.Trim))
        End If
        If txtPayOn.Text = "" Then
            objDB.AddParameter("PaymentDate", Data.SqlDbType.DateTime, DBNull.Value)
        Else
            objDB.AddParameter("PaymentDate", Data.SqlDbType.DateTime, Date.ParseExact(txtPayOn.Text.Trim, "dd-MMM-yyyy", Nothing))
        End If
        If txtRequisition.Text = "" Then
            objDB.AddParameter("Requisition", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("Requisition", Data.SqlDbType.NChar, txtRequisition.Text.ToUpper.Trim)
        End If
        objDB.AddParameter("PaymentType", Data.SqlDbType.TinyInt, CInt(ddlModeOfPayment.SelectedValue))
        If chkVendorCompany.Checked Then
            objDB.AddParameter("VendorType", Data.SqlDbType.TinyInt, 1)
            objDB.AddParameter("VendorName1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorName2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorName3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorCompany", Data.SqlDbType.NVarChar, txtVendorCompanyName.Text.ToUpper.Trim)
            objDB.AddParameter("VendorNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorCompanyNo", Data.SqlDbType.NVarChar, txtVendorCompanyNo.Text.ToUpper.Trim)
        Else
            objDB.AddParameter("VendorType", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("VendorName1", Data.SqlDbType.NVarChar, txtVendorName1.Text.ToUpper.Trim)
            objDB.AddParameter("VendorName2", Data.SqlDbType.NVarChar, txtVendorName2.Text.ToUpper.Trim)
            objDB.AddParameter("VendorName3", Data.SqlDbType.NVarChar, txtVendorName3.Text.ToUpper.Trim)
            objDB.AddParameter("VendorCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorNRIC1", Data.SqlDbType.NVarChar, txtVendorNric1.Text.ToUpper.Trim)
            objDB.AddParameter("VendorNRIC2", Data.SqlDbType.NVarChar, txtVendorNric2.Text.ToUpper.Trim)
            objDB.AddParameter("VendorNRIC3", Data.SqlDbType.NVarChar, txtVendorNric3.Text.ToUpper.Trim)
            objDB.AddParameter("VendorCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
        End If
        If txtVendorContactPerson.Text = "" Then
            objDB.AddParameter("VendorContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorContactPerson", Data.SqlDbType.NVarChar, txtVendorContactPerson.Text.ToUpper.Trim)
        End If
        If txtVendorAddress.Text = "" Then
            objDB.AddParameter("VendorAddress", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorAddress", Data.SqlDbType.NVarChar, txtVendorAddress.Text.ToUpper.Trim)
        End If
        If txtVendorPhone.Text = "" Then
            objDB.AddParameter("VendorPhone", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorPhone", Data.SqlDbType.NVarChar, txtVendorPhone.Text.ToUpper.Trim)
        End If
        If txtVendorMobile.Text = "" Then
            objDB.AddParameter("VendorMobile", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorMobile", Data.SqlDbType.NVarChar, txtVendorMobile.Text.ToUpper.Trim)
        End If
        If txtVendorFax.Text = "" Then
            objDB.AddParameter("VendorFax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorFax", Data.SqlDbType.NVarChar, txtVendorFax.Text.ToUpper.Trim)
        End If
        If txtVendorEmail.Text = "" Then
            objDB.AddParameter("VendorEmail", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorEmail", Data.SqlDbType.NVarChar, txtVendorEmail.Text.ToUpper.Trim)
        End If
        If ddlVendorRefer.SelectedValue = "1" Then
            objDB.AddParameter("VendorReferral", Data.SqlDbType.TinyInt, 1)
            If txtVendorReferName.Text = "" Then
                objDB.AddParameter("VendorReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorReferralName", Data.SqlDbType.NVarChar, txtVendorReferName.Text.ToUpper.Trim)
            End If
            If txtVendorReferNRIC.Text = "" Then
                objDB.AddParameter("VendorReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorReferralNRIC", Data.SqlDbType.NVarChar, txtVendorReferNRIC.Text.ToUpper.Trim)
            End If
            If txtVendorReferContact.Text = "" Then
                objDB.AddParameter("VendorReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("VendorReferralContact", Data.SqlDbType.NVarChar, txtVendorReferContact.Text.ToUpper.Trim)
            End If
            objDB.AddParameter("VendorReferralStatus", Data.SqlDbType.TinyInt, ddlVendorReferStatus.SelectedValue)
            If txtVendorReferAmt.Text = "" Then
                objDB.AddParameter("VendorReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("VendorReferralAmount", Data.SqlDbType.Decimal, CDbl(txtVendorReferAmt.Text.Trim))
            End If
        Else
            objDB.AddParameter("VendorReferral", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("VendorReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("VendorReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            objDB.AddParameter("VendorReferralStatus", Data.SqlDbType.TinyInt, ddlVendorReferStatus.SelectedValue)
        End If
        If txtVendorSolicitorCompName.Text = "" Then
            objDB.AddParameter("VendorSolicitorCompany", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorSolicitorCompany", Data.SqlDbType.NVarChar, txtVendorSolicitorCompName.Text.ToUpper.Trim)
        End If
        If txtVendorSolicitorContactPerson.Text = "" Then
            objDB.AddParameter("VendorSolicitorName", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorSolicitorName", Data.SqlDbType.NVarChar, txtVendorSolicitorContactPerson.Text.ToUpper.Trim)
        End If
        If txtVendorSolicitorEmail.Text = "" Then
            objDB.AddParameter("VendorSolicitorEmail", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorSolicitorEmail", Data.SqlDbType.NVarChar, txtVendorSolicitorEmail.Text.ToUpper.Trim)
        End If
        If txtVendorSolicitorsAddress.Text = "" Then
            objDB.AddParameter("VendorSolicitorAddress", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorSolicitorAddress", Data.SqlDbType.NVarChar, txtVendorSolicitorsAddress.Text.ToUpper.Trim)
        End If
        If txtVendorSolicitorsPhone.Text = "" Then
            objDB.AddParameter("VendorSolicitorPhone", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorSolicitorPhone", Data.SqlDbType.NVarChar, txtVendorSolicitorsPhone.Text.ToUpper.Trim)
        End If
        If txtVendorSolicitorsFax.Text = "" Then
            objDB.AddParameter("VendorSolicitorFax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("VendorSolicitorFax", Data.SqlDbType.NVarChar, txtVendorSolicitorsFax.Text.ToUpper.Trim)
        End If
        If chkPurcCompany.Checked Then
            objDB.AddParameter("PurchaserType", Data.SqlDbType.TinyInt, 1)
            objDB.AddParameter("PurchaserName1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserName2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserName3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserCompany", Data.SqlDbType.NVarChar, txtPurcCompanyName.Text.ToUpper.Trim)
            objDB.AddParameter("PurchaserNRIC1", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserNRIC2", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserNRIC3", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserCompanyNo", Data.SqlDbType.NVarChar, txtPurcCompanyNo.Text.ToUpper.Trim)
        Else
            objDB.AddParameter("PurchaserType", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("PurchaserName1", Data.SqlDbType.NVarChar, txtPurcName1.Text.ToUpper.Trim)
            objDB.AddParameter("PurchaserName2", Data.SqlDbType.NVarChar, txtPurcName2.Text.ToUpper.Trim)
            objDB.AddParameter("PurchaserName3", Data.SqlDbType.NVarChar, txtPurcName3.Text.ToUpper.Trim)
            objDB.AddParameter("PurchaserCompany", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserNRIC1", Data.SqlDbType.NVarChar, txtPurcNric1.Text.ToUpper.Trim)
            objDB.AddParameter("PurchaserNRIC2", Data.SqlDbType.NVarChar, txtPurcNric2.Text.ToUpper.Trim)
            objDB.AddParameter("PurchaserNRIC3", Data.SqlDbType.NVarChar, txtPurcNric3.Text.ToUpper.Trim)
            objDB.AddParameter("PurchaserCompanyNo", Data.SqlDbType.NVarChar, DBNull.Value)
        End If
        If txtPurcContactPerson.Text = "" Then
            objDB.AddParameter("PurchaserContactPerson", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserContactPerson", Data.SqlDbType.NVarChar, txtPurcContactPerson.Text.ToUpper.Trim)
        End If
        If txtPurcAddress.Text = "" Then
            objDB.AddParameter("PurchaserAddress", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserAddress", Data.SqlDbType.NVarChar, txtPurcAddress.Text.ToUpper.Trim)
        End If
        If txtPurcPhone.Text = "" Then
            objDB.AddParameter("PurchaserPhone", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserPhone", Data.SqlDbType.NVarChar, txtPurcPhone.Text.ToUpper.Trim)
        End If
        If txtPurcMobile.Text = "" Then
            objDB.AddParameter("PurchaserMobile", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserMobile", Data.SqlDbType.NVarChar, txtPurcMobile.Text.ToUpper.Trim)
        End If
        If txtPurcFax.Text = "" Then
            objDB.AddParameter("PurchaserFax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserFax", Data.SqlDbType.NVarChar, txtPurcFax.Text.ToUpper.Trim)
        End If
        If txtPurcEmail.Text = "" Then
            objDB.AddParameter("PurchaserEmail", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserEmail", Data.SqlDbType.NVarChar, txtPurcEmail.Text.ToUpper.Trim)
        End If
        If ddlPurcRefer.SelectedValue = "1" Then
            objDB.AddParameter("PurchaserReferral", Data.SqlDbType.TinyInt, 1)
            If txtPurcReferName.Text = "" Then
                objDB.AddParameter("PurchaserReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserReferralName", Data.SqlDbType.NVarChar, txtPurcReferName.Text.ToUpper.Trim)
            End If
            If txtPurcReferNRIC.Text = "" Then
                objDB.AddParameter("PurchaserReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserReferralNRIC", Data.SqlDbType.NVarChar, txtPurcReferNRIC.Text.ToUpper.Trim)
            End If
            If txtPurcReferContact.Text = "" Then
                objDB.AddParameter("PurchaserReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            Else
                objDB.AddParameter("PurchaserReferralContact", Data.SqlDbType.NVarChar, txtPurcReferContact.Text.ToUpper.Trim)
            End If
            objDB.AddParameter("PurchaserReferralStatus", Data.SqlDbType.TinyInt, ddlPurcReferStatus.SelectedValue)
            If txtPurcReferAmt.Text = "" Then
                objDB.AddParameter("PurchaserReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            Else
                objDB.AddParameter("PurchaserReferralAmount", Data.SqlDbType.Decimal, CDbl(txtPurcReferAmt.Text.Trim))
            End If
        Else
            objDB.AddParameter("PurchaserReferral", Data.SqlDbType.TinyInt, 0)
            objDB.AddParameter("PurchaserReferralName", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserReferralNRIC", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserReferralContact", Data.SqlDbType.NVarChar, DBNull.Value)
            objDB.AddParameter("PurchaserReferralAmount", Data.SqlDbType.Decimal, CDbl(0.0))
            objDB.AddParameter("PurchaserReferralStatus", Data.SqlDbType.TinyInt, ddlPurcReferStatus.SelectedValue)
        End If
        If txtPurcSolicitorCompName.Text = "" Then
            objDB.AddParameter("PurchaserSolicitorCompany", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserSolicitorCompany", Data.SqlDbType.NVarChar, txtPurcSolicitorCompName.Text.ToUpper.Trim)
        End If
        If txtPurcSolicitorContactPerson.Text = "" Then
            objDB.AddParameter("PurchaserSolicitorName", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserSolicitorName", Data.SqlDbType.NVarChar, txtPurcSolicitorContactPerson.Text.ToUpper.Trim)
        End If
        If txtPurcSolicitorEmail.Text = "" Then
            objDB.AddParameter("PurchaserSolicitorEmail", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserSolicitorEmail", Data.SqlDbType.NVarChar, txtPurcSolicitorEmail.Text.ToUpper.Trim)
        End If
        If txtPurcSolicitorsAddress.Text = "" Then
            objDB.AddParameter("PurchaserSolicitorAddress", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserSolicitorAddress", Data.SqlDbType.NVarChar, txtPurcSolicitorsAddress.Text.ToUpper.Trim)
        End If
        If txtPurcSolicitorsPhone.Text = "" Then
            objDB.AddParameter("PurchaserSolicitorPhone", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserSolicitorPhone", Data.SqlDbType.NVarChar, txtPurcSolicitorsPhone.Text.ToUpper.Trim)
        End If
        If txtPurcSolicitorsFax.Text = "" Then
            objDB.AddParameter("PurchaserSolicitorFax", Data.SqlDbType.NVarChar, DBNull.Value)
        Else
            objDB.AddParameter("PurchaserSolicitorFax", Data.SqlDbType.NVarChar, txtPurcSolicitorsFax.Text.ToUpper.Trim)
        End If
        'Fee
        If txtVendorAgencyFee.Text = "" Then
            objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("AgencyFee", Data.SqlDbType.Decimal, CDbl(txtVendorAgencyFee.Text.Trim))
        End If
        If txtVendorGsts.Text = "" Then
            objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("GST", Data.SqlDbType.Decimal, CDbl(txtVendorGsts.Text.Trim))
        End If
        If chkVendorGstPaid.Checked Then
            objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 1)
        Else
            objDB.AddParameter("GSTPaidBy", Data.SqlDbType.TinyInt, 0)
        End If
        If lblListingPercent.Text = "" Then
            objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("ListingFee", Data.SqlDbType.Decimal, CDbl(lblListingPercent.Text.Trim))
        End If
        If lblVendorReferralAmt.Text = "" Then
            objDB.AddParameter("VendorReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("VendorReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblVendorReferralAmt.Text.Trim))
        End If
        If txtPurcDisbursement.Text = "" Then
            objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("DisbursementFee", Data.SqlDbType.Decimal, CDbl(txtPurcDisbursement.Text.Trim))
        End If
        If lblPurcReferralAmt.Text = "" Then
            objDB.AddParameter("PurchaserReferralAmtSum", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("PurchaserReferralAmtSum", Data.SqlDbType.Decimal, CDbl(lblPurcReferralAmt.Text.Trim))
        End If
        If lblTotalAgencyFee.Text = "" Then
            objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("TotalAgencyFee", Data.SqlDbType.Decimal, CDbl(lblTotalAgencyFee.Text.Trim))
        End If
        If lblForLister.Text = "" Then
            objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("ListerAmt", Data.SqlDbType.Decimal, CDbl(lblForLister.Text.Trim))
        End If
        If lblReferral.Text = "" Then
            objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("ReferralAmt", Data.SqlDbType.Decimal, CDbl(lblReferral.Text.Trim))
        End If
        If lblForGorv.Text = "" Then
            objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("GovAmt", Data.SqlDbType.Decimal, CDbl(lblForGorv.Text.Trim))
        End If
        'If lblForCompany.Text = "" Then
        '    objDB.AddParameter("CompanyAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        'Else
        '    objDB.AddParameter("CompanyAmt", Data.SqlDbType.Decimal, CDbl(lblForCompany.Text.Trim))
        'End If
        'If lblForTransactor.Text = "" Then
        '    objDB.AddParameter("TransactorAmt", Data.SqlDbType.Decimal, CDbl(0.0))
        'Else
        '    objDB.AddParameter("TransactorAmt", Data.SqlDbType.Decimal, CDbl(lblForTransactor.Text.Trim))
        'End If
        If lblGrossAmount.Text = "" Then
            objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(0.0))
        Else
            objDB.AddParameter("GrossAmount", Data.SqlDbType.Decimal, CDbl(lblGrossAmount.Text.Trim))
        End If

        objDB.ExecuteQuery()
    End Sub

    Protected Sub btnBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBack.Click
        Dim strBack As String = Session("Back").ToString
        Dim arr() As String = strBack.Split("ڡ")
        Response.Redirect(arr(0).ToString)
    End Sub
End Class
